package com.tjh4.connection;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

/**
 * @ClassName DruidTest
 * @Description : Druid连接测试
 * @Author tang'jia'hao
 * @Date 2021/9/25 19:07
 * @Version 1.0
 **/
public class DruidTest {

    @Test
    public void getConnection() throws Exception {
//        DruidDataSource source = new DruidDataSource();
        Properties pros = new Properties();

        InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("druid.properties");
        pros.load(is);

        DataSource source = DruidDataSourceFactory.createDataSource(pros);
        Connection conn = source.getConnection();
        System.out.println("conn = " + conn);


    }
}
